package cn.cvs.logape;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
public class LogAop {
    private static final Logger log = Logger.getLogger(LogAop.class);



    @Pointcut("execution(public void cn.cvs.service.impl.UserServiceImpl(*))")
    public void q(){

    }

    @Before("q()")
    public void before(JoinPoint joinPoint){
            log.info("调用"+joinPoint.getTarget()+"的"+joinPoint.getSignature().getName()+"方法.方法入参"
                    + Arrays.toString(joinPoint.getArgs()));

    }

    @AfterReturning(pointcut = "q()",returning = "result")
    public void afterReturning(JoinPoint joinPoint,Object result){
        log.info("调用"+joinPoint.getTarget()+"的"+joinPoint.getSignature().getName()+"方法.方法返回值"
                +result);
    }
}
